home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 501-525 / disk_521 / a68k / a68k271.lzh / A68kglb.h < prev    next >
C/C++ Source or Header  |  1991-04-16  |  12KB  |  271 lines

  1. /*------------------------------------------------------------------*/
  2. /*                                    */
  3. /*            MC68000 Cross Assembler                */
  4. /*                                    */
  5. /*          Copyright 1985 by Brian R. Anderson            */
  6. /*                                    */
  7. /*                 Global variables - April 16, 1991            */
  8. /*                                    */
  9. /*   This program may be copied for personal, non-commercial use    */
  10. /*   only, provided that the above copyright notice is included        */
  11. /*   on all copies of the source code.  Copying for any other use   */
  12. /*   without the consent of the author is prohibited.            */
  13. /*                                    */
  14. /*------------------------------------------------------------------*/
  15. /*                                    */
  16. /*        Originally published (in Modula-2) in            */
  17. /*        Dr. Dobb's Journal, April, May, and June 1986.        */
  18. /*                                    */
  19. /*     AmigaDOS conversion copyright 1991 by Charlie Gibbs.        */
  20. /*                                    */
  21. /*------------------------------------------------------------------*/
  22.  
  23. #ifdef PRIMARY
  24. #define GLOBAL
  25. #else
  26. #define GLOBAL extern
  27. #endif
  28.  
  29. GLOBAL char SourceFN[MAXFN];    /* Source file name */
  30. GLOBAL char HeaderFN[MAXFN];    /* Header file name (-h) */
  31. GLOBAL char SrecFN[MAXFN];    /* Object file name (-o) */
  32. GLOBAL char InclList[MAXLINE];    /* List of directories to search (-i) */
  33. GLOBAL char IdntName[MAXLINE];    /* Program unit name */
  34.  
  35. struct fs {
  36.     int  fd;        /* File handle */
  37.     char *Buf;        /* Pointer to buffer */
  38.     char *Ptr;        /* Current position in buffer */
  39.     char *Lim;        /* Logical end of buffer */
  40. };
  41. GLOBAL struct fs In;    /* Input file */
  42. GLOBAL struct fs Eq;    /* Equate file */
  43. GLOBAL struct fs List;    /* Listing file */
  44. GLOBAL struct fs Srec;    /* Object file */
  45.  
  46. /*    Command-line options    */
  47.  
  48. GLOBAL int DumpSym;    /* -d Dump the symbol table. */
  49. GLOBAL char DumpSymList[MAXLINE];    /* -d selection list */
  50. GLOBAL int FwdProc;    /* -f Special processing for forward references */
  51. GLOBAL int GlobalXREF;    /* -g Make all unknown globals XREFed */
  52. GLOBAL int SuppList;    /* (neither -l nor -x) Suppress listing file. */
  53. GLOBAL long DataOffset;    /* -m Offset to small data base (normally 32767) */
  54. GLOBAL int NoOpt;    /* -n Suppress all optimization. */
  55. GLOBAL int LnMax;    /* -p Maximum number of lines per page */
  56. GLOBAL int Quiet;    /* -q Line no. display interval (0 to suppress) */
  57. GLOBAL int KeepTabs;    /* -t Keep tabs in the listing file. */
  58. GLOBAL long HashSize;    /* -w Number of entries in the hash table */
  59. GLOBAL int XrefList;    /* -x Produce a cross-reference listing. */
  60. GLOBAL int HashStats;    /* -y Display hashing statistics. */
  61. GLOBAL int DebugStart;    /* -z Debug display starts here. */
  62. GLOBAL int DebugEnd;    /* -z Debug display ends here. */
  63.  
  64. GLOBAL char TTLstring[MAXLINE];    /* Title string */
  65.  
  66. GLOBAL int  LabLine;        /* Last labeled line number */
  67. GLOBAL int  LineCount;        /* Source line counter */
  68. GLOBAL char Line[MAXLINE];    /* Current source line */
  69. GLOBAL char Label[MAXLINE];    /* Instruction label */
  70. GLOBAL char OpCode[MAXLINE];    /* Instruction mnemonic */
  71. GLOBAL char SrcOp[MAXLINE];    /* First (source) operand */
  72. GLOBAL char DestOp[MAXLINE];    /* Second (destination) operand */
  73. GLOBAL int  LabLoc, OpLoc;    /* Label and mnemonic start here */
  74. GLOBAL int  SrcLoc, DestLoc;    /* Operands start here. */
  75. GLOBAL int  Dir, PrevDir;    /* Assembler directive */
  76. GLOBAL int  NumSyms;        /* Number of symbols */
  77. GLOBAL long ObjOp;        /* OpCode object code */
  78. GLOBAL long ObjSrc;        /* Source operand object code */
  79. GLOBAL long ObjDest;        /* Destination operand object code */
  80. GLOBAL char ObjString[MAXLINE];    /* String data */
  81. GLOBAL int  nO, nS, nD, nX;    /* Length of above components */
  82. GLOBAL int  PrntAddr;        /* Print AddrCnt on listing. */
  83. GLOBAL int  MakeHunk;        /* We must make a hunk. */
  84. GLOBAL int  ListOff;        /* NOLIST is supressing listing lines. */
  85. GLOBAL int  LnCnt;        /* Number of lines on current page */
  86. GLOBAL int  PgCnt;        /* Page number */
  87. GLOBAL long Hunk2;        /* Hunk number (from GetValue) */
  88. GLOBAL int  DefLine2;        /* Definition line number */
  89. GLOBAL int  SingleFlag;        /* Expression consists of a single term. */
  90. GLOBAL int  GotEqur;        /* We have register equates. */
  91. GLOBAL int  SmallData;        /* Register for small data model (or -1) */
  92. GLOBAL int  AnyNear;        /* We got at least one NEAR directive. */
  93. GLOBAL int  FwdShort;        /* Forward reference could be made short. */
  94.  
  95. GLOBAL int  Pass2;    /* Pass 2 flag */
  96. GLOBAL long AddrCnt;    /* Location counter */
  97. GLOBAL long AddrAdv;    /* Bump AddrCnt by this much. */
  98. GLOBAL long DupFact;    /* Duplication factor for DCB, 1 otherwise */
  99. GLOBAL long OrgHigh;    /* Highest address reached if we ORG backwards */
  100. GLOBAL long OrgSeek;    /* Return here in Srec if we ORG backwards. */
  101. GLOBAL long EndAddr;    /* END statement transfer address */
  102. GLOBAL long SectStart;    /* Current section (or portion) starts here. */
  103. GLOBAL int  SectLine;    /* Line number where section started */
  104. GLOBAL int  HunkSeq;    /* Hunk sequence number */
  105. GLOBAL long HunkType;    /* Current hunk type */
  106. GLOBAL long HunkFlags;    /* Hunk flags (MEMF_FAST or MEMF_CHIP) */
  107. GLOBAL long CurrHunk;    /* Current hunk number */
  108. GLOBAL long NextHunk;    /* Next available hunk number */
  109. GLOBAL long LenPos;    /* Seek position of current hunk length */
  110. GLOBAL char *LenPtr;    /* Pointer to length if in buffer, else NULL */
  111. GLOBAL int  InclErrs;    /* Error processing INCLUDE statement(s) */
  112. GLOBAL int  InnrFMac;    /* An inner file has been read by a user macro. */
  113. GLOBAL int  OrgFlag;    /* ORG may require object file fixup. */
  114.  
  115. GLOBAL int  SFormat;    /* Generate S-record format. */
  116. GLOBAL long StartAddr;    /* Address that record starts on */
  117. GLOBAL long TempAddr;    /* Address of where we are now */
  118.  
  119. GLOBAL int  IncStart;    /* Start line number of skippable INCLUDE */
  120. GLOBAL struct InFCtl *IncPtr;    /* Copy of InF for skippable INCLUDE */
  121. struct SkipEnt {        /* Skippable INCLUDE description */
  122.     struct SetFixup *Set1;    /*  Pointer to first SET fixup */
  123.     int Start;            /*  Starting line number of INCLUDE */
  124.     int Finish;            /*  Ending line number of INCLUDE */
  125.     int MCount;            /*  Value of MacCount at end of INCLUDE */
  126. };
  127. struct SetFixup {        /* SET symbol fixup entry */
  128.     struct SymTab *Sym;        /* Pointer to symbol table entry */
  129.     long Val;            /* Fixup value */
  130.     long Hunk;            /* Fixup hunk number */
  131. };
  132. GLOBAL struct SkipEnt *SkipLim;    /* Logical end of skippable INCLUDEs */
  133. GLOBAL struct SkipEnt *SkipIdx;    /* Current skippable INCLUDE entry */
  134. GLOBAL struct SetFixup *SetFixLim;    /* Next available SetFixup */
  135.  
  136. struct SymTab {                /* Symbol table */
  137.     struct SymTab *Link;    /* Link to next entry in hash chain */
  138.     char *Nam;    /* Pointer to symbol */
  139.     long Val;    /* Value */
  140.     long Hunk;    /* Hunk number (ORed with MEMF_CHIP or MEM_FAST
  141.             if applicable SECTION
  142.            ~(pointer to symbol) if XREF
  143.            Pointer to macro text if MACRO        */
  144.     int  Defn;    /* Line number where defined */
  145.     int  Flags;    /* Flags bits:    0 - XREF
  146.                 1 - XDEF
  147.                 2 - SET
  148.                 3 - MACRO (symbol is preceded by blank)
  149.                 4 - SECTION (name preceded by 2 blanks
  150.                     and 4-digit hex sequence number)
  151.                 5 - register name (EQUR)
  152.                 6 - register list (REG)
  153.                 7 - PUBLIC (XREF or XDEF will be set) */
  154.     struct Ref *Ref1;    /* Pointer to first reference entry */
  155. };
  156. GLOBAL struct SymTab *SymStart;    /* The symbol table starts here. */
  157. GLOBAL struct SymTab *SymLim;    /* The symbol table ends here. */
  158. GLOBAL struct SymTab *SymCurr;    /* Start of current chunk of data */
  159. GLOBAL struct SymTab *Sym;    /* ReadSymTab sets this up. */
  160. GLOBAL struct SymTab *Sect;    /* Current section's entry */
  161. GLOBAL struct SymTab *SymChunk;    /* Current symbol chunk for NextSym */
  162. GLOBAL struct SymTab *SymChLim;    /* End of *SymChunk chunk */
  163. GLOBAL struct SymTab **Hash;    /* Pointer to hash table */
  164. GLOBAL struct SymTab **SymSort;    /* Symbol sort area */
  165. GLOBAL int  *HashCount;        /* Hashing summary table */
  166.  
  167. struct NameChunk {        /* Chunk of labels or macro text */
  168.     struct NameChunk *Link;    /* Link to the next chunk */
  169.     char *Data[CHUNKSIZE-sizeof(struct NameChunk *)];    /* Data area */
  170. };
  171. GLOBAL struct NameChunk *NameStart;    /* Start of first name chunk */
  172. GLOBAL char             *NameLim;    /* Next available name entry */
  173. GLOBAL struct NameChunk *NameCurr;    /* Start of current name chunk */
  174.  
  175. struct Ref {            /* Reference entry */
  176.     struct Ref *NextRef;    /* Pointer to next reference entry */
  177.     int RefNum[MAXREF];        /* Reference line numbers */
  178. };
  179. GLOBAL struct Ref *RefLim;    /* Next available reference entry */
  180.  
  181. struct RelTab {            /* Relocation table entry */
  182.     struct RelTab *Link;    /* Link to the next entry */
  183.     long Offset;        /* Offset to relocatable value */
  184.     long Hunk;            /* Hunk type to relocate relative to */
  185.     int  Size;            /* Size of relocatable value */
  186. };
  187. GLOBAL struct RelTab *RelStart;    /* Relocation data starts here */
  188. GLOBAL struct RelTab *RelLim;    /* Relocation data ends here */
  189. GLOBAL struct RelTab *RelCurr;    /* Start of current chunk of data */
  190. GLOBAL struct RelTab *RelLast;    /* Last relocation entry added */
  191.  
  192. struct TermStack {        /* Parser's term stack */
  193.     long value;            /* Value */
  194.     long hunk;            /* Hunk number */
  195.     int  oploc;            /* Location in source statement */
  196.     int  defline;        /* Line number where defined */
  197. };
  198. GLOBAL struct TermStack *Term;    /* Term stack pointer */
  199.  
  200. struct OpStack {        /* Parser's operator stack */
  201.     char chr;            /* Operator character */
  202.     int  prec;            /* Precedence */
  203. };
  204. GLOBAL struct OpStack *Ops;    /* Operator stack pointer */
  205.  
  206. GLOBAL char OpPrec[256];    /* Operator precedence look-up table */
  207.  
  208. GLOBAL int  InFNum;        /* Current input nesting level */
  209. struct InFCtl {
  210.     long Pos;            /* Current position in input */
  211.     char *UPtr;            /* Current position in user macro or 0 */
  212.     char *NPtr;            /* File name stack pointer */
  213.     int  Line;            /* Current line number in this file */
  214.     int  NArg;            /* Number of macro arguments or -1 */
  215.     int  MCnt;            /* Macro expansion number (for \@) */
  216. };
  217. GLOBAL struct InFCtl *InF;    /* Macro/include file stack pointer */
  218. GLOBAL struct InFCtl *LowInF;    /* "Low-water mark" for InF */
  219. GLOBAL char *Heap2;        /* Secondary heap */
  220. GLOBAL char *NextFNS;        /* Next input file path/name */
  221. GLOBAL char *High2;        /* Secondary high-water mark */
  222. GLOBAL char *Low2;        /* Low limit from top of heap */
  223.  
  224. GLOBAL int  OuterMac;        /* Level number of outermost macro */
  225. GLOBAL int  MacCount;        /* Number of macros expanded */
  226. GLOBAL int  SkipNest;        /* Skipped IF/ENDC nesting count */
  227. GLOBAL char MacSize[2];        /* Macro call size ("B", "W", or "L") */
  228.  
  229. struct OpConfig {        /* Operand configuration */
  230.     long Value;    /* Value */
  231.     long Hunk;    /* Hunk number */
  232.     int  Defn;    /* Line number where defined */
  233.     int  Mode;    /* Addressing mode */
  234.     int  Loc;    /* Location of operand on Line */
  235.     int  Rn;    /* Register number */
  236.     int  Xn;    /* Index register number */
  237.     int  Xsize;    /* Size of index */
  238.     int  X;    /* Is index Data or Address reg? */
  239.     int  Single; /* The operand is a single term. */
  240. };
  241. GLOBAL struct OpConfig Src, Dest;    /* Source and destination operands */
  242.  
  243. GLOBAL int Size;    /* Size for OpCode */
  244. GLOBAL int InstSize;    /* Size of instruction, including operands */
  245. GLOBAL int AdrModeA;    /* Addressing modes for this instruction */
  246. GLOBAL int AdrModeB;    /*                 ditto                 */
  247. GLOBAL int Op;        /* Raw bit pattern for OpCode */
  248.  
  249. GLOBAL struct FwdBr {    /* Forward branch optimization candidates */
  250.     long Loc;        /* Location of Bcc instruction */
  251.     struct SymTab *FwdSym;    /* Pointer to target label entry */
  252.     int  Line;        /* Line number (copied to FwdTable if OK) */
  253. } FwdBranch[64];
  254. GLOBAL struct FwdBr *FwdLim1;    /* Logical end of FwdBranch */
  255. GLOBAL struct SymTab *FwdBranchFix[128]; /* Symbol table entries to fix */
  256. GLOBAL struct SymTab **FwdFixLimit;    /* Logical end of fixup table */
  257.  
  258. struct FwdTable {
  259.     struct FwdTable *Link;
  260.     int FwdLine[(FWDSIZE-sizeof(struct FwdTable *)) / sizeof (int)];
  261. };
  262. GLOBAL struct FwdTable *FwdStart;    /* Start of first chunk */
  263. GLOBAL int             *FwdLim2;    /* Next available entry */
  264. GLOBAL struct FwdTable *FwdCurr;    /* Start of current chunk */
  265. GLOBAL int             *FwdPtr;        /* Current position in pass 2 */
  266.  
  267. GLOBAL int ErrorCount;
  268.  
  269. /* Error message tables */
  270. GLOBAL int ErrLim, ErrCode[ERRMAX], ErrPos[ERRMAX];
  271.